package com.example.phone.account.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.phone.R;
import com.example.phone.base.BaseFragment;
import com.example.phone.base.MyApp;
import com.example.phone.base.RequestInterface;
import com.example.phone.bean.User;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2019\1\2 0002.
 */

public class AccountFragment extends Fragment {
    private View mContentView;
    Intent intent;

    @BindView(R.id.wait_paying)
    LinearLayout waitPaying;
    @BindView(R.id.wait_receving)
    LinearLayout waitReceving;
    @BindView(R.id.all_orders)
    LinearLayout allOrders;
    @BindView(R.id.address_manage)
    TextView addressManage;
    @BindView(R.id.ci_head_portrait)
    CircleImageView ciHeadPortrait;
    @BindView(R.id.account_name)
    TextView account_name;

    /**
     * 是否登录
     */
    private boolean is_login = true;
    private User user;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContentView = inflater.inflate(initLayout(), container, false);
        ButterKnife.bind(this,mContentView);
        init();
        initView();
        initData();

        return mContentView;
    }

    private void initData() {
        MyApp myApp = (MyApp)getActivity().getApplication();
        user = myApp.getUser();
        Intent intent = new Intent();

        if(user == null){

        }
        else {
            String imagePath = RequestInterface.baseImgPath + user.getHeadPortraitUrl();
            String name = user.getUsername();
            account_name.setText(name);

//            Glide.with(this)
//                    .load(imagePath)
//                    .into(ciHeadPortrait);
        }

    }

    private void initView() {
    }

    private void init() {
    }

    private int initLayout() {
        return R.layout.my_accout_layout;
    }

    @OnClick({R.id.wait_paying, R.id.wait_receving, R.id.all_orders, R.id.address_manage, R.id.ci_head_portrait})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.wait_paying:
                break;
            case R.id.wait_receving:

                intent = new Intent(getActivity().getApplicationContext(),WaitPayActivity.class);
                startActivity(intent);

                break;
            case R.id.all_orders:

                break;
            case R.id.address_manage:
                if (is_login) {
                    //用户登录   跳转到地址管理界面
                    intent = new Intent(getActivity().getApplicationContext(), ManageActivity.class);

                    startActivity(intent);
                } else {
                    //未登录
                }
                break;

            case R.id.ci_head_portrait:

                intent = new Intent(getActivity().getApplicationContext(), PersonInfomationActivity.class);
                startActivity(intent);
                break;
        }
    }
}
